package com.cy.sys.shiro;

import java.util.LinkedHashMap;

import org.apache.shiro.cache.CacheManager;
import org.apache.shiro.cache.MemoryConstrainedCacheManager;
import org.apache.shiro.mgt.RememberMeManager;
import org.apache.shiro.realm.Realm;
import org.apache.shiro.spring.web.config.DefaultShiroFilterChainDefinition;
import org.apache.shiro.spring.web.config.ShiroFilterChainDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

	/**
	 * 	1.配置SpringShiroConfig类创建对象提供注解@Configuration
	 * @author Administrator
	 *
	 */
@Configuration//此注解描述的类为spring的配置类
public class SpringShiroConfig {
		
	@Bean
	public Realm realm() {		
		return new shiroAuthenSerivce();  
	}

	@Bean
	public ShiroFilterChainDefinition shiroFilterChainDefinition() {
	    DefaultShiroFilterChainDefinition chainDefinition = new DefaultShiroFilterChainDefinition();
	    
	    LinkedHashMap<String,String> map= new LinkedHashMap<>();
        //静态资源允许匿名访问:"anon"
        map.put("/bower_components/**","anon");
        map.put("/build/**","anon");
        map.put("/dist/**","anon");
        map.put("/plugins/**","anon");
        map.put("/user/doLogin","anon");
        map.put("/doLogout","anon");
        //除了匿名访问的资源,其它都要认证("authc")后访问
        map.put("/**","user");
        chainDefinition.addPathDefinitions(map);
	    return chainDefinition;
	}
	
	@Bean
	protected CacheManager shirocacheManager() {
	    return new MemoryConstrainedCacheManager();
	}
	
	
}
